<html>
	<head>
	
		<?php
        INCLUDE "header.php";
	    if(isset($_POST["data"]))
		{
		$data = $_POST["data"];
		$obs = $_POST["obs"];
		$idfazenda = $_POST["idfazenda"];
		$idvacina = $_POST["idvacina"];
		$idanimal = $_POST["idanimal"];
		
        $sql = "INSERT INTO vacinacao(data, obs, idfazenda, idvacina, idanimal ) 
		
		values('$data', '$obs','$idfazenda','$idvacina','$idanimal')";
		echo $sql;
		pg_query($sql);
		
		
		$mensagem = "Dados cadastrados com sucesso!";
	    echo "<p style=\"color:green; margin-top:20px; margin-left:10px;\">".$mensagem."</p>";
	    }
		
		//aqui recebe os dados para alteração
		if(isset($_GET["id"]) == false)
		{
			header("listarVacinacao.php");
		}
		$id = $_GET["id"];
		$sql = "select * from vacinacao where id=$id";
		$resultado = pg_query($sql);
		$linha = pg_fetch_assoc($resultado);
		
        ?>
		
		
	</head>
	<body>
		<feeldset>
		
	

      <form action="cadastroVacinacao.php" method="post">
		<div class="pull-right"> 
		<div class="btn" title="nova vacinacao"><i class="icon-edit"></i><a></a></div>
		<div class="btn" title="sair"><i class="icon-share-alt"></i><a></a></div>
		</div>
       
		<legend><i class="icon-edit"></i>Cadastro de vacinação</legend>
		<div id="ok" name="certo" style="display:none;"><?php $sucesso = '<span  class="yes">Item inserido com sucesso!</span>';?></div>

			<div class="controls controls-row">
		<div class="control-group span">
		
			<label>id</label>
			<input type="text" class="input-large" redyonly name="id" value="<?php echo $linha["id"]?> "/>
			
			
			
		</div>
		</div>
		<div class="controls controls-row">
		<div class="control-group span">
		
		<label>Data</label>
			<input type="date" class="input-large" placeholder="__/__/__" name="data" value="<?php echo $linha["data"]?>"></input>
		</div>
		</div>
	
		<div class="controls controls-row">
		<div class="control-group span">
		
		<label>Observação</label>
			<input type="text" class="input-large" placeholder="observação" name="obs" value="<?php echo $linha["obs"]?>"></input>
		</div>
		</div>
		<div class="controls controls-row">
		<div class="control-group span">
		<label>Fazenda</label>
		<select name="idfazenda">
		<?php
		$sql = "select * from fazenda order by nome";
		$res = pg_query($sql);
		$optFazenda = "";
		while ($linha=pg_fetch_assoc($res))
		{
		$id = $linha["id"];
		$nome = $linha["nome"];
		if($vacinacao["id"] == $item["idfazenda"])
		{
		$optFazenda = $optFazenda. "<option value='$id' selected>$nome</option>";
		}
		else
		{
		$optFazenda = $optFazenda. "<option value='$id'>$nome</option>";
		}
		}
		?>
		<option value="">selecione..</option>
		<?php echo $optFazenda; ?>
	
		</select>
		
		</div>
		</div>
		<div class="controls controls-row">
		<div class="control-group span">
		<label>Vacina</label>
		<select name="idvacina">
		
		<?php
		$sql = "select * from vacina order by nome";
		$res = pg_query($sql);
		$optVacina = "";
		while ($linha=pg_fetch_assoc($res))
		{
		$id = $linha["id"];
		$nome = $linha["nome"];
		if($vacinacao["id"] == $item["idvacina"])
		{
		$optVacina = $optVacina. "<option value='$id' selected>$nome</option>";
		}
		else
		{
		$optVacina .= "<option value='$id'>$nome</option>";
		}
		}
		?>
		<option value="">selecione..</option>
		<?php echo $optVacina; ?></select>
		</div>
		</div>
		<div class="controls controls-row">
		<div class="control-group span">
		<label>Animal</label>
		<select name="idanimal">
		<?php
		$sql = "select * from animal order by nome";
		$res = pg_query($sql);
		$optAnimal = "";
		while ($linha=pg_fetch_assoc($res))
		{
		$id = $linha["id"];
		$nome = $linha["nome"];
		
		if($vacinacao["id"] == $item["idanimal"])
		{
		$optAnimal = $optAnimal. "<option value='$id' selected>$nome</option>";
		}
		else
		{
		$optAnimal .= "<option value='$id'>$nome</option>";
		}
		}
		?>
		<option value="">selecione..</option>
		<?php echo $optAnimal; ?></select>
		</div>
		</div>
		<div class="form-actions">
		<div class="pull-right">
			<button class="btn btn-success" name="salvar" type="submit" value="enviar"><i class="icon-ok icon-white"></i> salvar</button>
			<button class="btn btn"><i class="icon-trash"></i> limpar campos</button>
		</div>
		</div>
		
		
		</form>
		<!--<div class="input-append">
		<input class="span3"/>
		<button class="btn" type="button" >GO!</button
		</div>-->
		</feeldset>
	</body>
</html>